<?php


namespace App\Http\Services\FormBuilder;


class FormItemFactory
{
    private $typeList = [
        'text' => \App\Http\Services\FormBuilder\Elements\Text::class,
        'textarea' => \App\Http\Services\FormBuilder\Elements\TextArea::class,
        'password' => \App\Http\Services\FormBuilder\Elements\Password::class,
        'number' => \App\Http\Services\FormBuilder\Elements\Number::class,
        'address' => \App\Http\Services\FormBuilder\Elements\Address::class,
        'select' => \App\Http\Services\FormBuilder\Elements\Select::class,
        'date' => \App\Http\Services\FormBuilder\Elements\Date::class,
        'checkbox' => \App\Http\Services\FormBuilder\Elements\Checkbox::class,
        'radio' => \App\Http\Services\FormBuilder\Elements\RadioButton::class,
        'file' => \App\Http\Services\FormBuilder\Elements\File::class,
        'split' => \App\Http\Services\FormBuilder\Elements\Split::class,
        'editor' => \App\Http\Services\FormBuilder\Elements\Editor::class,
    ];


    public function getItem($type, $param)
    {
        try {
            if ($type == 'date' ) {
                //dd($param);
            }
            $className = $this->typeList[$type];
            return new $className($param);
        } catch (\Exception $exception) {
            // @TODO 默认不创建或默认创建一个文本 待定
            return new $this->typeList['text'];
        }
    }
}
